package com.kerbores.jfinal.interceptor;

import org.apache.commons.lang3.time.StopWatch;
import org.apache.log4j.Logger;

import com.jfinal.aop.Interceptor;
import com.jfinal.core.ActionInvocation;
import com.kerbores.jfinal.controller.base.BaseController;

/**
 * @author 王贵源
 *
 *         create at 2014年9月22日 下午9:18:25
 */
public class LogInterceptor implements Interceptor {
	Logger log = Logger.getRootLogger();

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.jfinal.aop.Interceptor#intercept(com.jfinal.core.ActionInvocation)
	 */
	@Override
	public void intercept(ActionInvocation ai) {
		log.debug("Before Invoke Method:" + ai.getController().getClass().getSimpleName() + "." + ai.getMethodName() + "  Parameters:" + ai.getController().getParaMap());
		StopWatch sw = new StopWatch();
		sw.start();
		ai.invoke();
		sw.stop();
		log.debug("After Invoke render data:" + ((BaseController) ai.getController()).getResult() + " Time escape :" + sw.getTime() + " ms(" + sw.getNanoTime() + "ns)");
	}

}
